#ifndef DATABSE_EXCUTOR_H
#define DATABSE_EXCUTOR_H

#include "Tool.hpp"
#include "Object/Object.hpp"
#include "Paser.hpp"
#include "../base/TimeUnit.hpp"
#include "../base/Defind.hpp"

#include <unordered_map>
#include <string>
#include <functional>

namespace DBServer
{
namespace Database
{

class Excutor{
public:
    using CallBack = std::function<void(Excutor &ex, Object &, CommandRequest &&, CommandRespond &)>;

    DEFAULT_NULL_CONSTUCTOR(Excutor);
    NONCOPY_NONMOVE_CONSTRUCTOR(Excutor);

    int excute_commen(Object& oo, CommandRespond& rep, CommandRequest&& req, com_func_t& cft);
    int excute(Object& oo, CommandRespond& rep, CommandRequest&& req, com_func_t& cft);

private:
    /**
     * base command:
     * 1. TTL       KEY     // set the expire time for a key
     * 2. TYPE      KEY     // get the type name of the specifial key
     * 3. ALIVE     KEY     // get the specifical key's alive time
    */
    auto ttl(Object&, unsigned long long) -> bool;

    auto type(Object&) -> std::string;

    auto alive(Object&) -> unsigned long long;

private:
    // base command use for object(base class of object)
    static std::unordered_map<int, CallBack> cb_table;
    // database timer
    DBServer::Base::Timer::Time db_timer;
};
    
} // namespace Databse
} // namespace DBServer


#endif